/*
 * @Author: wangqizhang
 * @Date: 2024-04-26 14:24:40
 * @LastEditors: wangqizhang
 * @LastEditTime: 2024-05-07 11:05:29
 * @FilePath: /suixinji-server/main.js
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
const Koa = require('koa');
const { koaBody } = require('koa-body');
const { getNormalConfig } = require('./config/config');
const cors = require('@koa/cors');
const corsOptions = {
  origin: '*',
  allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
  allowHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
};
const app = new Koa();
// app.use(cors(corsOptions));
app.use(koaBody());
app.use(cors(corsOptions));
//引入路由
const userRouter = require('./router/user.router');
const groupRouter = require('./router/group.router');
const noterRouter = require('./router/note.router');
//注册路由
app.use(userRouter.routes());
app.use(groupRouter.routes());
app.use(noterRouter.routes());

//启动服务
const VAR_PORT = getNormalConfig('VAR_PORT');
console.log(VAR_PORT);
app.listen(VAR_PORT, () => {
  console.log('服务运行在 http://localhost:' + VAR_PORT);
});
